<?php

namespace App\Console\Commands;

use Bschmitt\Amqp\Facades\Amqp;
use Illuminate\Console\Command;

class SendEmailConsumeMQ extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'consumer01';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     * @throws \Exception
     */
    public function handle()
    {
        $this->info('Start...');
        Amqp::consume('HelloWorld', function ($message, $resolver){
            $end = microtime(true);
            $start = $message->body;
            $duration = $end - $start;
            $this->info($duration.'----'.$start);
            $resolver->acknowledge($message);
        });
        return 0;
    }
}
